
/***
 * String 格式替换,
 * 如：var s="this is a {0}"; s = s.format('hello');
 * 如：var s="this is a {msg}"; s = s.format({msg:'hello'});
 * @param args
 * @returns {String}
 */
String.prototype.format = function(args) {
    var result = this;
    if (arguments.length > 0) {    
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                if(args[key]!=undefined){
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
                    var reg = new RegExp("({[" + i + "]})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
};

String.prototype.trim = function() {
	  var str = this,
	  str = str.replace(/^\s\s*/, ''),
	  ws = /\s/,
	  i = str.length;
	  while (ws.test(str.charAt(--i)));
	  return str.slice(0, i + 1);
}



